//////////////////////////////////////////////////////////////////////
//
//	Copyright 2010-2011 Rogo's Team. All Rights Reserved
//
//////////////////////////////////////////////////////////////////////
package com.rogo.weibo.platform.netease.api.hot
{
	import com.rogo.weibo.core.DoAPI;
	import com.rogo.weibo.platform.netease.api.oauth.Oauth;
	import com.rogo.weibo.utils.HttpParameter;
	import com.rogo.weibo.utils.OauthUrlUtil;
	
	import flash.net.URLRequestMethod;
	
	import json.JSON;
	
	public class DoHot extends DoAPI
	{
		public function DoHot(dataHandler:Function, errorHandler:Function)
		{
			super(dataHandler, errorHandler);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Constants
		//
		//--------------------------------------------------------------------------
		
		private static const URL_HOT:String = 'http://api.t.163.com/statuses/topRetweets/type.json';
		public static const CMD_HOT:String = 'cmdHot';
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		/**
		 * 获取当前的热门转发榜
		 * 
		 * @param type 必选参数，排行榜类型,当前有4种:oneHour,sixHours,oneDay,oneWeek
		 * @param size 可选参数，返回数量,不传则为默认值(当前为50),最多50
		 */		
		public function getHot(type:String, size:String):void
		{
			var paras:Array = [];
			if (type != null)
				paras.push(new HttpParameter('type', type));
			if (size != null)
				paras.push(new HttpParameter('size', size));
			Oauth.currentAccountKey.httpMethod = URLRequestMethod.GET;
			var url:String = OauthUrlUtil.getOauthUrl(URL_HOT, 
				Oauth.currentAccountKey.httpMethod, 
				Oauth.currentAccountKey.consumerKey, 
				Oauth.currentAccountKey.consumerSecret,
				Oauth.currentAccountKey.tokenKey,
				Oauth.currentAccountKey.tokenSecrect,
				Oauth.currentAccountKey.verify,
				Oauth.currentAccountKey.callbackUrl,
				paras);
			send(url, resultHandler, errorHandler);
			
			function resultHandler(params:String):void
			{
				resultResponse(CMD_HOT, params);
			}
			
			function errorHandler(params:String):void
			{
				errorResponse(CMD_HOT, params);
			}
		}
		
		private function resultResponse(cmd:String, params:String):void
		{
			var data:Object = JSON.decode(params);
			_dataHandler(cmd, data);
		}
		
		private function errorResponse(cmd:String, params:String):void
		{
			var data:Object = JSON.decode(params);
			_errorHandler(cmd, data);
		}
		
	}
}